package com.ali.common;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class StreamUtil {
    /**
     * InputStream转化为字节数组
     */
    public static byte[] readInputStream(InputStream inputStream) {
        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
            byte[] bytes = new byte[1024];
            int length = 0;
            while ((length = inputStream.read(bytes)) != -1) {
                byteArrayOutputStream.write(bytes, 0, length);
            }
            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}